import { Col, Row, Spin } from 'antd';
import { useEffect } from 'react';
import { connect } from 'umi';
import { getAnnounceByIDService } from '../services';
import '../common/styles.less';
import { AnnounceHomeLeft } from './AnnounceHomeLeft';
import React from 'react';

const AnnounceHomeView: React.FC<AnnounceHomeAPI.IAnnounceHomeView> = ({
  curRes,
  locationProps,
}) => {
  const prefixCls = 'announcehome-preview-';

  const {
    getAnnounceInfoObj,
    getAnnounceInfoRun,
    getAnnounceLoading,
  } = getAnnounceByIDService();

  useEffect(() => {
    if (locationProps?.state?.id) {
      let infoPayload = {
        ...locationProps?.state,
      };
      getAnnounceInfoRun(infoPayload);
    }
  }, [locationProps?.state]);

  return (
    <>
      <Spin spinning={getAnnounceLoading}>
        <Row className={prefixCls + 'row'}>
          <Col span={24} className={prefixCls + 'row-col'}>
            <AnnounceHomeLeft
              announceInfoObj={getAnnounceInfoObj}
              prefixCls={prefixCls}
            />
          </Col>
        </Row>
      </Spin>
    </>
  );
};

export default connect(({ baseLogin, navTab }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
  navTab,
}))(AnnounceHomeView);
